package com.dj.mingkong.portal.biz.controller.music;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dj.mingkong.common.annotation.RequestLimit;
import com.dj.mingkong.common.infrastructure.base.dto.page.PageVo;
import com.dj.mingkong.common.infrastructure.base.dto.rest.RestResponse;
import com.dj.mingkong.common.microservice.UserContext;
import com.dj.mingkong.common.util.AssertUtils;
import com.dj.mingkong.common.util.SmartBeanCopy;
import com.dj.mingkong.portal.biz.controller.music.vo.request.MusicianFansAddVo;
import com.dj.mingkong.portal.biz.controller.music.vo.request.MusicianFansCancelVo;
import com.dj.mingkong.portal.biz.controller.music.vo.request.MusicianFansQueryVo;
import com.dj.mingkong.portal.biz.controller.music.vo.request.MusicianFansUserQueryVo;
import com.dj.mingkong.portal.biz.controller.music.vo.response.MusicianFansDetailVo;
import com.dj.mingkong.portal.biz.controller.music.vo.response.MusicianFansUserVo;
import com.dj.mingkong.portal.biz.controller.music.vo.response.MusicianFansVo;
import com.dj.mingkong.portal.biz.service.music.MusicianFansService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 音乐人粉丝管理
 *
 * @author zenglonghui
 * @date: 2022/8/25 10:40
 */
@RestController
@RequestMapping("/musician/fans")
public class MusicianFansController {
    @Resource
    private MusicianFansService musicianFansService;

    /**
     * 添加音乐人粉丝
     *
     * @param addVo {}
     * @return Boolean
     */
    @PostMapping("/add")
    @RequestLimit(count = 5)
    public RestResponse<Boolean> add(@RequestBody @Validated MusicianFansAddVo addVo) {
        musicianFansService.add(addVo);
        return RestResponse.buildSuccess();
    }

    /**
     * 关注音乐人
     *
     * @param addVo 实例对象
     * @return 是否成功，true-成功，false-失败
     */
    @PostMapping("/follow")
    @RequestLimit(count = 10)
    public RestResponse<Boolean> follow(@RequestBody @Validated MusicianFansAddVo addVo) {
        musicianFansService.follow(addVo);
        return RestResponse.buildSuccess();
    }

    /**
     * 获取音乐人关注信息
     *
     * @param musicianId 音乐人id
     * @return 是否成功，true-成功，false-失败
     */
    @GetMapping("/getMusicianFans/{musicianId}")
    public RestResponse<MusicianFansDetailVo> getMusicianFans(@PathVariable("musicianId") Long musicianId) {
        return RestResponse.success(musicianFansService.getMusicianFans(musicianId));
    }

    /**
     * 分页查询关注的音乐人列表
     *
     * @param queryVo {}
     * @return MusicianVo
     */
    @PostMapping("/pageByVo")
    public RestResponse<PageVo<MusicianFansVo>> pageByVo(@RequestBody MusicianFansQueryVo queryVo) {
        AssertUtils.checkQueryPageVo(queryVo);
        queryVo.setUserId(UserContext.getUserId());
        final Page<MusicianFansVo> musicianFansVoPage = musicianFansService.pageByVo(queryVo);
        final PageVo<MusicianFansVo> pageVo = SmartBeanCopy.copyPageVo(musicianFansVoPage, MusicianFansVo.class);
        return RestResponse.success(pageVo);
    }

    /**
     * 获取粉丝用户数据列表
     *
     * @param queryVo {}
     * @return UserFansVo
     */
    @PostMapping("/user/pageByVo")
    public RestResponse<PageVo<MusicianFansUserVo>> pageUserByVo(@RequestBody @Validated MusicianFansUserQueryVo queryVo) {
        AssertUtils.checkQueryPageVo(queryVo);
        queryVo.setUserId(UserContext.getUserId());
        final Page<MusicianFansUserVo> musicianFansUserVoPage = musicianFansService.pageUserByVo(queryVo);
        final PageVo<MusicianFansUserVo> pageVo = SmartBeanCopy.copyPageVo(musicianFansUserVoPage, MusicianFansUserVo.class);
        return RestResponse.success(pageVo);
    }

    /**
     * 取消关注
     *
     * @param cancelVo {}
     * @return Boolean
     */
    @PostMapping("/cancel")
    @RequestLimit(count = 5)
    public RestResponse<Boolean> cancel(@RequestBody @Validated MusicianFansCancelVo cancelVo) {
        musicianFansService.cancel(cancelVo);
        return RestResponse.buildSuccess();
    }
}
